const HtmlWebpackPlugin = require("html-webpack-plugin");
var webpack = require("webpack");
const merge = require("webpack-merge");
const baseConfig = require("./webpack.base");
console.log("process.env.NODE_ENV", process.env.NODE_ENV);
let entry = {
  app: "./src/example.js" // 测试入口
};
function resolve(dir) {
  return path.join(__dirname, "..", dir);
}
let config = {};
// 编译browser和weapp的配置
// 微信
if (process.env.NODE_ENV === "weapp") {
  config = {
    entry: {
      "mogo-sdk-wx": "./src/mogo-wx.js"
    },
    plugins: [
      new webpack.BannerPlugin({
        banner:
          "var window={};var XMLHttpRequest;var navigator;var localStorage;",
        raw: true
      })
    ]
  };
}
// 浏览器
if (process.env.NODE_ENV === "browser") {
  config = {
    entry: {
      "mogo-sdk": "./src/index.js"
    },
    output: {
      libraryTarget: "window"
    },
    plugins: [
      new HtmlWebpackPlugin({
        filename: "index.html",
        template: "index.html"
      })
    ]
  };
}
if (process.env.NODE_ENV === "development") {
  config = {
    entry: {
      app: "./src/example.js"
    },
    output: {
      libraryTarget: "window"
    },
    plugins: [
      new HtmlWebpackPlugin({
        filename: "index.html",
        template: "index.html"
      })
    ]
  };
}

const totalConfig = merge(baseConfig, config);
module.exports = totalConfig;
